<%@ page language="java" contentType="text/html;charset=utf-8" pageEncoding="UTF-8" trimDirectiveWhitespaces="true"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="f" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>添加角色</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<jsp:include page="../common.jsp"/>
	<!--树组件start -->
	<script type="text/javascript" src="libs/js/tree/ztree/ztree.js"></script>
	<link href="libs/js/tree/ztree/ztree.css" rel="stylesheet" type="text/css"/>
	<!--树组件end -->
	<script type="text/javascript">
		var zTreeObj;
		var zNodes =${jsonString };
		var setting = {
			check: {enable: true,chkboxType: { "Y": "ps", "N": "s" }},
			data: {simpleData: {enable: true}},
			callback: {onClick: onClick}
		};
		$(function(){
			zTreeObj = $.fn.zTree.init($("#treeDemo"), setting, zNodes);
			$("#submit_button").click(function() {
				var nodes=zTreeObj.getCheckedNodes();
				for ( var i = 0; i < nodes.length; i++) {
					var text="<input type='hidden' name='pubResources["+i+"].resourceId' value='"+nodes[i].id+"'>";
					$(document.forms[0]).append(text);
				}
				document.forms[0].submit();
			});
		});
		function onClick(e, treeId, treeNode) {
			zTreeObj.checkNode(treeNode, !treeNode.checked, true, true);
		}
	</script>
  </head>
  <body>
  	<f:form action="sys/role/doAdd" modelAttribute="role">
		<div class="box1" panelWidth="100%">
		<fieldset> 
			<legend>新增角色</legend> 
			<table class="tableStyle" formMode="transparent" footer="normal">
				<tr>
					<td width="15%">角色名称：</td>
					<td width="35%">
						<f:input path="roleName"/>
						<span class="star">*</span>
						<f:errors path="roleName" cssStyle="color:red"/>
					</td>
				</tr>
				<tr>
					<td width="15%">角色描述：</td>
					<td>
						<f:textarea path="roleDesc"/>
					</td>
				</tr>
				<tr>
					<td width="15%">启用状态：</td>
					<td>
						<f:radiobuttons path="enabled" items="${status }"/>
					</td>
				</tr>
				<tr>
					<td width="15%" valign="top">资源列表：</td>
					<td>
						<div><ul id="treeDemo" class="ztree"></ul></div>
						<span class="star">*</span>
						<f:errors path="pubResources" cssStyle="color:red"/>
					</td>
				</tr>
			</table>
		</fieldset> 
		<div class="height_5"></div>
		<div class="padding_top10">
			<table class="tableStyle" formMode="transparent">
				<tr>
					<td colspan="4">
						<input type="button" value="提交" id="submit_button">
						<input type="button" value="返回" onclick="location.href='<%=basePath%>sys/role/list'"/>
					</td>
				</tr>
			</table>
		</div> 
	</div>
	</f:form>
  </body>
</html>
